Skip to content

fix(functions): send a res.send number as JSON and ignore a second argument, as deployed functions do - #311

Merged
chhavi-mandowara-cstk merged 6 commits into
v2-devfrom
CL-8970
Nov 26, 2026
Merged

chhavi-mandowara-cstk merged 6 commits into
v2-devfrom
CL-8970

Conversation

@chhavi-mandowara-cstk

@chhavi-mandowara-cstk chhavi-mandowara-cstk commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What was wrong

In launch:functions:serve, res.send(42) answered 500. Express 4 treats a lone number as a deprecated status argument; 42 is not a valid status, so writeHead throws and the route answers 500.

Deployed AWS functions (lambda-node-bridge/cf-sv-with-helpers.ts in contentfly-deployment-agent) use the same send/json helpers as Vercel's @vercel/node (checked in 33.0.0; even the res.redirect 307 default and its error message match word for word). Their res.send takes one argument, and a number goes through json():

Call AWS / Vercel serve before serve after
res.send(42) 200, 42, application/json; charset=utf-8 500 same as AWS
res.send(NaN) 200, null, JSON 200 NaN* same as AWS
res.status(201).send(418) 201, 418, JSON 500 same as AWS
content type already set + res.send(7) keeps it (text/plain; charset=utf-8), 7 500 same as AWS
res.send(404, 'x') 200, 404, JSON (second argument ignored) 404, x same as AWS
res.send('x', 410) 200, x, text/html 410, x same as AWS

* NaN is not a valid status either, so Express 4 throws on it too.

The ticket owner chose this exact parity over keeping Express's two-argument forms.

The change

  • src/functions/cloud-functions.ts: the sendLikeDeployedFunctions middleware replaces res.send with a one-argument version: a number goes to Express's res.json (JSON.stringify, application/json unless a content type is already set, current status), and everything else goes to Express's send with only its first argument.
  • AGENTS.md: the approved V1 differences now describe res.send and res.redirect, and what Azure/GCP (V1, Express 4) still do: res.send(404) as a 404 status, res.send(42) as 500, and the two-argument forms honoured.
  • .talismanrc: refreshed checksums for cloud-functions.test.ts and AGENTS.md (test code and prose, no credentials).

Tests

  • src/functions/cloud-functions.test.ts: two regression tests. The number cases (42, 0, status 201 + 418, NaN, a preset content type) failed with 500 before the fix. The second-argument cases failed with Express's 404/410.
  • Mutation check: sending the number as a string instead of JSON turns both tests red.
  • File: 69/69. Full suite in the pre-push hook: 201 suites, 4114 tests passed.

E2E (http-sanity cloud-functions checks, AWS expectations)

Ran every check in contentfly-e2e-tests fixtures/http-sanity-cloud-functions.json against launch:functions:serve built from each side, serving fixtures/http-sanity-cloud-functions:

  • v2-dev cb5c2bb: 7/15
  • this branch: 8/15. res.send(number) sends the number now passes; no other check changed.

No e2e change is needed: the check already exists, and its Azure/GCP knownGaps entry (500) stays until those clouds run the v2 CLI.

Known gaps

  • res.json still accepts Express 4's two-argument forms locally (res.json(404, body) sets 404), while deployed AWS/Vercel res.json takes one argument. This was there before this PR and is outside gap 3; added to CL-8970's gap list as a follow-up.

Notes

  • Hooks: every commit and the push ran the full hooks (lint-staged, Talisman, trufflehog, Snyk, and the full suite on push), no --no-verify. ggshield is not installed in this environment, so its new hook step printed its skip notice.
  • The branch has the earlier iterations as separate commits (no squash, per the owner).

QA: the Launch QA agent tests CL-8970 in the repos once it is in QA; GoCD sanity covers dev11.

Jira: https://contentstack.atlassian.net/browse/CL-8970

res.send(42) made functions:serve answer 500 because Express treats a number
as a deprecated status argument. Deployed functions send the number as the
body with a 200 status, so convert a number to its string before Express
sees it.
…umber

Forward every argument to Express's send and convert only a lone number,
so res.send(404, 'x') and res.send('x', 404) keep their status. Record the
res.redirect and res.send(number) behaviour in the approved V1 differences.
…gument

Deployed functions (lambda-node-bridge, the same helpers as Vercel's
@vercel/node) take one argument in res.send and send a number through
json(): res.send(42) answers 200 with 42 as application/json, NaN as null,
and res.send(404, 'x') ignores the 'x'. Match that instead of sending the
number as text/html and honouring Express's two-argument forms, and correct
the approved V1 differences in AGENTS.md.
The res.send note in AGENTS.md is prose; Talisman flags its punctuation
as low-severity patterns. No credentials.
@snyk-io

snyk-io Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

Copy link
Copy Markdown

🔒 Security Scan Results

ℹ️ Note: Only vulnerabilities with available fixes (upgrades or patches) are counted toward thresholds.

Check Type Count (with fixes) Without fixes Threshold Result
🔴 Critical Severity 0 0 10 ✅ Passed
🟠 High Severity 0 2 25 ✅ Passed
🟡 Medium Severity 0 1 500 ✅ Passed
🔵 Low Severity 0 0 1000 ✅ Passed

⏱️ SLA Breach Summary

✅ No SLA breaches detected. All vulnerabilities are within acceptable time thresholds.

Severity Breaches (with fixes) Breaches (no fixes) SLA Threshold (with/no fixes) Status
🔴 Critical 0 0 15 / 30 days ✅ Passed
🟠 High 0 0 30 / 120 days ✅ Passed
🟡 Medium 0 0 90 / 365 days ✅ Passed
🔵 Low 0 0 180 / 365 days ✅ Passed

ℹ️ Vulnerabilities Without Available Fixes (Informational Only)

The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:

  • Critical without fixes: 0
  • High without fixes: 2
  • Medium without fixes: 1
  • Low without fixes: 0

✅ BUILD PASSED - All security checks passed

@chhavi-mandowara-cstk
chhavi-mandowara-cstk merged commit 3604ddc into v2-dev Nov 26, 2026
7 checks passed
@chhavi-mandowara-cstk
chhavi-mandowara-cstk deleted the CL-8970 branch November 26, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants